<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>couchdb.json</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css" />
  <script type="text/javascript" src="epydoc.js"></script>
</head>

<body bgcolor="white" text="black" link="blue" vlink="#204080"
      alink="#204080">
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="couchdb-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            ><a class="navbar" target="_top" href="../index.html">Documentation Index</a></th>
          </tr></table></th>
  </tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="100%">
      <span class="breadcrumbs">
        <a href="couchdb-module.html">Package&nbsp;couchdb</a> ::
        Module&nbsp;json
      </span>
    </td>
    <td>
      <table cellpadding="0" cellspacing="0">
        <!-- hide/show private -->
      </table>
    </td>
  </tr>
</table>
<!-- ==================== MODULE DESCRIPTION ==================== -->
<h1 class="epydoc">Module json</h1><p class="nomargin-top"></p>
<p>Thin abstraction layer over the different available modules for decoding
and encoding JSON data.</p>
<dl class="rst-docutils">
<dt>This module currently supports the following JSON modules:</dt>
<dd><ul class="rst-first rst-last rst-simple">
<li><tt class="rst-docutils literal"><span class="pre">simplejson</span></tt>: <a class="rst-reference external" href="http://code.google.com/p/simplejson/" target="_top">http://code.google.com/p/simplejson/</a></li>
<li><tt class="rst-docutils literal"><span class="pre">cjson</span></tt>: <a class="rst-reference external" href="http://pypi.python.org/pypi/python-cjson" target="_top">http://pypi.python.org/pypi/python-cjson</a></li>
<li><tt class="rst-docutils literal"><span class="pre">json</span></tt>: This is the version of <tt class="rst-docutils literal"><span class="pre">simplejson</span></tt> that is bundled with the
Python standard library since version 2.6
(see <a class="rst-reference external" href="http://docs.python.org/library/json.html" target="_top">http://docs.python.org/library/json.html</a>)</li>
</ul>
</dd>
</dl>
<p>The default behavior is to use <tt class="rst-docutils literal"><span class="pre">simplejson</span></tt> if installed, and otherwise
fallback to the standard library module. To explicitly tell CouchDB-Python
which module to use, invoke the <a href="couchdb.json-module.html#use" class="link">use()</a> function with the module name:</p>
<pre class="rst-literal-block">
from couchdb import json
json.use('cjson')
</pre>
<p>In addition to choosing one of the above modules, you can also configure
CouchDB-Python to use custom decoding and encoding functions:</p>
<pre class="rst-literal-block">
from couchdb import json
json.use(decode=my_decode, encode=my_encode)
</pre>

<!-- ==================== FUNCTIONS ==================== -->
<a name="section-Functions"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td align="left" colspan="2" class="table-header">
    <span class="table-header">Functions</span></td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">object</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="couchdb.json-module.html#decode" class="summary-sig-name">decode</a>(<span class="summary-sig-arg">string</span>)</span><br />
      Decode the given JSON string.</td>
          <td align="right" valign="top">
            
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">basestring</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="couchdb.json-module.html#encode" class="summary-sig-name">encode</a>(<span class="summary-sig-arg">obj</span>)</span><br />
      Encode the given object as a JSON string.</td>
          <td align="right" valign="top">
            
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="couchdb.json-module.html#use" class="summary-sig-name">use</a>(<span class="summary-sig-arg">module</span>=<span class="summary-sig-default">None</span>,
        <span class="summary-sig-arg">decode</span>=<span class="summary-sig-default">None</span>,
        <span class="summary-sig-arg">encode</span>=<span class="summary-sig-default">None</span>)</span><br />
      Set the JSON library that should be used, either by specifying a known
module name, or by providing a decode and encode function.</td>
          <td align="right" valign="top">
            
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
</table>
<!-- ==================== FUNCTION DETAILS ==================== -->
<a name="section-FunctionDetails"></a>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td align="left" colspan="2" class="table-header">
    <span class="table-header">Function Details</span></td>
</tr>
</table>
<a name="decode"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">decode</span>(<span class="sig-arg">string</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    >&nbsp;
    </td>
  </tr></table>
  
  Decode the given JSON string.
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>string</code></strong> (basestring) - the JSON string to decode</li>
    </ul></dd>
    <dt>Returns: object</dt>
        <dd>the corresponding Python data structure</dd>
  </dl>
</td></tr></table>
</div>
<a name="encode"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">encode</span>(<span class="sig-arg">obj</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    >&nbsp;
    </td>
  </tr></table>
  
  Encode the given object as a JSON string.
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>obj</code></strong> (object) - the Python data structure to encode</li>
    </ul></dd>
    <dt>Returns: basestring</dt>
        <dd>the corresponding JSON string</dd>
  </dl>
</td></tr></table>
</div>
<a name="use"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">use</span>(<span class="sig-arg">module</span>=<span class="sig-default">None</span>,
        <span class="sig-arg">decode</span>=<span class="sig-default">None</span>,
        <span class="sig-arg">encode</span>=<span class="sig-default">None</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    >&nbsp;
    </td>
  </tr></table>
  
  <p>Set the JSON library that should be used, either by specifying a known
module name, or by providing a decode and encode function.</p>
<p>The modules &quot;simplejson&quot;, &quot;cjson&quot;, and &quot;json&quot; are currently supported for
the <tt class="rst-docutils literal"><span class="pre">module</span></tt> parameter.</p>
<p>If provided, the <tt class="rst-docutils literal"><span class="pre">decode</span></tt> parameter must be a callable that accepts a
JSON string and returns a corresponding Python data structure. The
<tt class="rst-docutils literal"><span class="pre">encode</span></tt> callable must accept a Python data structure and return the
corresponding JSON string. Exceptions raised by decoding and encoding
should be propagated up unaltered.</p>
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>module</code></strong> (str or module) - the name of the JSON library module to use, or the module
object itself</li>
        <li><strong class="pname"><code>decode</code></strong> (callable) - a function for decoding JSON strings</li>
        <li><strong class="pname"><code>encode</code></strong> (callable) - a function for encoding objects as JSON strings</li>
    </ul></dd>
  </dl>
</td></tr></table>
</div>
<br />
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="couchdb-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            ><a class="navbar" target="_top" href="../index.html">Documentation Index</a></th>
          </tr></table></th>
  </tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
  <tr>
    <td align="left" class="footer">
    Generated by Epydoc 3.0.1 on Mon Dec 14 15:25:33 2009
    </td>
    <td align="right" class="footer">
      <a target="mainFrame" href="http://epydoc.sourceforge.net"
        >http://epydoc.sourceforge.net</a>
    </td>
  </tr>
</table>

<script type="text/javascript">
  <!--
  // Private objects are initially displayed (because if
  // javascript is turned off then we want them to be
  // visible); but by default, we want to hide them.  So hide
  // them unless we have a cookie that says to show them.
  checkCookie();
  // -->
</script>
</body>
</html>
